package com.tubang.logistics.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tubang.common.util.StringUtils;
import com.tubang.logistics.entity.ShipperOrderEntity;
import com.tubang.logistics.mapper.ShipperOrderMapper;
import com.tubang.logistics.service.IShipperOrderService;
import com.tubang.logistics.vo.ChangeStatusVo;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;

/**
 * <p>
 * 货主运单表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2017-12-31
 */
@Service
public class ShipperOrderServiceImpl extends ServiceImpl<ShipperOrderMapper, ShipperOrderEntity> implements IShipperOrderService {

    @Override
    public void updateSupplyOrderStatus(ChangeStatusVo changeStatusVo) {
        ShipperOrderEntity order = selectById(changeStatusVo.getOrderId());
        if (order == null) return;
        order.setStatusCode(changeStatusVo.getThisStatus());
        order.setStatusCodeDesc(changeStatusVo.getThisStatusDesc());
        Double carriage = changeStatusVo.getCarriage();
        if (carriage != null) {
            order.setCarriageDeal(carriage);
            Double carriageNow = order.getCarriage();
            Double amountNow = order.getAmount();
            double amountDeal = (amountNow / carriageNow)*carriage;
            order.setAmountDeal(Double.valueOf(new DecimalFormat("#.00").format(amountDeal)));
        }
        String remarks = changeStatusVo.getRemarks();
        if (StringUtils.isNotEmpty(remarks)) {
            order.setRemarks(remarks);
        }
        order.setCarrier(changeStatusVo.getCid());
        order.setCarrierMobile(changeStatusVo.getCmobile());
        order.setCarrierId(changeStatusVo.getCid());
        insertOrUpdate(order);
    }
}
